 /***************************************************************
 * 配置文件
 * 
 * 进度：
 * PWM ok
 * ADC ok
 * LED ing
 * 
 * 
 * 
 * *************************************************************/
#ifndef _CONFIGURATION_H_
#define _CONFIGURATION_H_

//#include "STC8H.H"

/*******************宏定义**********************/
#define pwm_period fosc/pwm_freq-1         //周期时间
//#define pwm_duty   
#define pwm_freq 25000                      //pwm频率 25khz

#define sc_freq 500                         //测速模拟频率  15000rpm（500hz）

#define fosc 33177600UL                     //主频33.1776M

#define pwm_out 0x01                            //pwm输出引脚P17  (0x01) pwm5   ||| PWMB_ENO       -  ENO8P   -   ENO7P   -   ENO6P   -   ENO5P   1生效
 
#define sc_out 0x10                            //          P14  (0x10) pwm3p  ||| PWMA_ENO    ENO4N ENO4P ENO3N ENO3P ENO2N ENO2P ENO1N ENO1P   1生效          

#define Temp P10                               //NTC电压adc读取引脚

#define LED P3                                 //LED引脚    数码管

#define SCout  P14                             //测速模拟信号输出引脚

#define fan_en P15                              //风扇开关

#define _td P12                      //十位片选

#define _sd P13                     //个位片选

#define key_input P54                        //按键检测

#define resis  99000                           //ntc分压电阻   单位0.1Ω

#define shumaguan_shanshuo_slow 20              //数码管慢闪间隔定义   30=亮0.5秒，灭0.5秒

#define shumaguan_shanshuo_quick 5             //数码管快闪间隔定义

#define _OFF_ 0                                 

#define _ON_ 1          

#define _HYS_UD_ 1                               //温控延迟双向

#define _HYS_U_ 2                                //温控升延迟

#define _HYS_D_ 3                               //温控降延迟

#define _settings_dat_count_ 39                 //设置数据字节计数

/******************变量声明*******************/


extern unsigned char data _temp;             //当前温度
extern unsigned char data _temp0;            //缓存温度

extern unsigned char data _control_point_count;

extern unsigned char data _display_on;          //显示开关
extern unsigned char data_5000ms_ok;          
     
extern unsigned char data _10ms_ok;      //按键检测标志


extern unsigned char data _1000ms_ok;      //1s计时标志
extern unsigned char data _5000ms_ok;        //5s计时标志
extern unsigned char data _30000ms_ok;       //30s计时标志
/*******************************结构体声明********************************/

typedef struct                           //全部设置保存变量
{
    struct settings_f0
    {
        struct _l              //温控曲线变量
        {
            char en;                                    //开关
            char temp;                               //温度点
            char duty;                                  //占空比
        }l[10];                                       //10个控制点
    }f0;                                                
    struct setting_f1                           //风扇关停设置  1关停
    {
        char en;                                //开关
        char temp;                              //关停温度
    }f1;
    char f2;                           //风扇控制模式设置   0：0-100   1：100-0   2：100-20    
    struct setting_f3                           //温控延迟
    {
        char mode;                          //延迟模式
        char hys;                           //上升延迟温度
 //       char hys_down;                      //下降延迟温度
    }f3;
    struct setting_f4
    {
        char always;                                      //常亮显示开关 0关闭
        char brightness;                             //亮度数值（OF-5）
    }f4;
    struct setting_f5                 //手动模式设置
    {
        char mode;                                       //手动开关 au:0:温控模式   of:1:手动模式
        char duty;                                      //手动占空比
    }f5;        
 
}setting;


typedef struct {
    unsigned char menu_l;
    unsigned char dis_tenth; unsigned char dis_dig;
    unsigned int buf;
    void (*func)(char);
}setting_menu;


typedef struct
{
    struct setting_addr_f0
    {
        struct addr_l
        {
            unsigned int en;
            unsigned int temp;
            unsigned int duty;
        }l[10];/*={
        {0x0000,0x0001,0x0002},{0x0003,0x0004,0x0005},{0x0006,0x0007,0x0008},{0x0009,0x000a,0x000b},
        {0x000c,0x000d,0x000e},{0x000f,0x0010,0x0011},{0x0012,0x0013,0x0014},
        {0x0015,0x0016,0x0017},{0x0018,0x0019,0x001a},{0x001b,0x001c,0x001d}
        };*/

    }f0;
    struct addr_f1
    {
        unsigned int en/*=0x001e*/;
        unsigned int temp/*=0x001f*/;
    }f1;
    unsigned int f2/*=0x0020*/;

    struct addr_f3
    {
        unsigned int mode/*=0x0021*/;
        unsigned int hys/*=0x0022*/;

    }f3;
    struct addr_f4
    {
        unsigned int always/*=0x0024*/;
        unsigned int brightness/*=0x0025*/;
    }f4;
    struct addr_f5
    {
        unsigned int mode/*=0x0026*/;
        unsigned int duty/*=0x0027*/;
    }f5;
    unsigned char count;
//    unsigned int dis_mode/*=0x0028*/;
}setting_addr;

typedef enum{
    _root_,
    f0_temp_control,
    control_point,
    l_en,
    l_temp,
    l_duty,
    f1_auto_off,
    auto_off_en,
    auto_off_temp,
    f2_pwm_mode,
    pwm_mode,
    f3_hys_set,
    hys_mode,
    hys_temp,
    f4_dis_set,
    dis_al_on,
    dis_brightness,
    f5_manual,
    manual_en,
    manual_duty,
    _menu_count_
}menu_enum;


extern setting settings;

extern code setting_addr settings_addr;

extern setting_menu menu[];

extern void settings_init();

extern void Timer0_Init(void);

#endif